package com.hpxx.ylzswl.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hpxx.ylzswl.R;
import com.hpxx.ylzswl.bean.MessageBean;
import com.hpxx.ylzswl.utils.ViewHolder;
import com.universal.frame.generalutils.DateUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/11/9.
 */

public class MessageAdapter extends BaseAdapter{

    private Context context;
    private List<MessageBean> list;

    public MessageAdapter(Context context, List<MessageBean> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public MessageBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        MessageBean bean = getItem(position);
        if(view == null){
            view = View.inflate(context, R.layout.item_message,null);
        }

        TextView tv_text = ViewHolder.get(view,R.id.tv_message_text);
        tv_text.setText(bean.noticeContent);
        TextView tv_time = ViewHolder.get(view,R.id.tv_message_time);
        tv_time.setText(DateUtil.starmpToData(bean.createTime));
        View v_off = ViewHolder.get(view,R.id.v_off);
        if ("0".equals(bean.noticeStatus)){
            v_off.setVisibility(View.VISIBLE);
        }else if ("1".equals(bean.noticeStatus)){
            v_off.setVisibility(View.INVISIBLE);
        }
        return view;
    }
}
